/*
 * Ext JS Library 2.2
 * Copyright(c) 2006-2008, Ext JS, LLC.
 * licensing@extjs.com
 *
 * http://extjs.com/license
 */

Ext.onReady(function(){

    Ext.Ajax.request({

        url: 'http://localhost:8080/presto/edge/api',
        method:"POST",
        timeout:60000,
        params:{
            "inputStream": "{'version': '1.1','sid': 'StockCodeRetriever','svcVersion':'0.1','oid': 'invoke','params': ['choco']}"
        },
        success:function(response){
            var first = Ext.util.JSON.decode(response.responseText);
            var second = Ext.util.JSON.decode(first.response);
            var third = second.resultado;
            var fin = third.length-1;
            var jsonFinal = third.substring(39,fin);
            console.log(Ext.util.JSON.decode(jsonFinal));
        }
    });

    var jsonstore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
        url:'http://localhost:8080/presto/edge/api',
        method:"POST",
        timeout:60000,
        params:{
            "inputStream": "{'version': '1.1','sid': 'StockCodeRetriever','svcVersion':'0.1','oid': 'invoke','params': 'choco']}"
        }
    }),
        reader: new Ext.data.JsonReader({
            root:'ResultSet.Result',
            fields:[{name:'exch'}]
    })
    });


    var grid = new Ext.grid.GridPanel({
        renderTo: document.body,
        frame:true,
        title: 'Stock Codes',
        height:200,
        width:500,
        store:jsonstore,
        columns:[
            {header: "Exchange", width: 100, sortable: true, dataIndex: 'exch'},
    ]
    });
});
